#include "MSE_ROOT_INIT.h"
#include "MY_define.h"
#include "MSE_DBUS.h"
#include "usart.h"

struct MSE_ROOT_Typedef MSE_ROOT ={ 0 };

void MSE_F_ROOT(void)
{
    MSE_F_ROOT_ALL_STATUS();
    MSE_F_MASTER_LOCATION_JUDGE();
}

uint8_t MSE_F_MOTOR_STATUS(struct MSE_MOTOR_Typedef* MOTOR)
{
    MOTOR->DATA.ONLINE_JUDGE_TIME--;

    if (MOTOR->DATA.ONLINE_JUDGE_TIME < 5)
    {
        MOTOR->DATA.ONLINE_JUDGE_TIME = 0;
        return MSE_DF_OFFLINE;
    }
    else
    {
        return MSE_DF_ONLINE;
    }
}

void MSE_F_ROOT_ALL_STATUS(void)
{
	
	if (MSE_V_DBUS_ONLINE_JUDGE_TIME < 5)
	{
		MSE_V_DBUS_ONLINE_JUDGE_TIME = 3;
		MSE_ROOT.STATUS.RM_DBUS = MSE_DF_OFFLINE;
	}
	else
	{
		MSE_ROOT.STATUS.RM_DBUS = MSE_DF_ONLINE;
	}
	MSE_V_DBUS_ONLINE_JUDGE_TIME--;
	
	MSE_ROOT.STATUS.MOTOR_HEAD_Yaw          = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_Yaw);
	MSE_ROOT.STATUS.MOTOR_HEAD_Left         = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_L_CUP_PUMP);
	MSE_ROOT.STATUS.MOTOR_HEAD_Right        = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_R_CUP_PUMP);
	MSE_ROOT.STATUS.MOTOR_HEAD_SWAY         = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_SWAY);
	MSE_ROOT.STATUS.MOTOR_HEAD_LIFT_L       = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_LIFT_L );
	MSE_ROOT.STATUS.MOTOR_HEAD_LIFT_R       = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_LIFT_R );
	MSE_ROOT.STATUS.MOTOR_CHASSIS_3508_1    = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_BOTTOM_3508_1);
    MSE_ROOT.STATUS.MOTOR_CHASSIS_3508_2    = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_BOTTOM_3508_2);
    MSE_ROOT.STATUS.MOTOR_CHASSIS_3508_3    = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_BOTTOM_3508_3);
    MSE_ROOT.STATUS.MOTOR_CHASSIS_3508_4    = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_BOTTOM_3508_4);
	MSE_ROOT.STATUS.MOTOR_HEAD_HORIZONTAL_L = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_HORIZONTAL_L);
    MSE_ROOT.STATUS.MOTOR_HEAD_HORIZONTAL_R = MSE_F_MOTOR_STATUS(&MSE_V_MOTOR_HORIZONTAL_R);
}
	
uint8_t MSE_F_MASTER_LOCATION_JUDGE(void)
{
	MSE_ROOT.MASTER_LOCATION = MSE_DF_MASTER_LOCATION_HEAD;
	return MSE_DF_READY;        
}